﻿Public Class ChangePwd
    Dim dt As New DataTable
    Private Sub ChangePwd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadtype()
        loaddata()
        txtid.Text = dt.Rows(0).Item(1)
        txtid.Enabled = False
        cbogroup.SelectedValue = dt.Rows(0).Item(2)
        cbogroup.Enabled = False
        txtname.Text = dt.Rows(0).Item(3)
        txtpwd.Text = dt.Rows(0).Item(4)
    End Sub

    Private Sub loaddata()
        cmd.Parameters("@id") = MainMenu.userid
        dt = cmd.ExecuteDataTable("SELECT * FROM user_tbl WHERE user_id=@id")
    End Sub
    
    Private Sub loadtype()
        cbogroup.ValueMember = "user_type_id"
        cbogroup.DisplayMember = "user_type"
        cbogroup.DataSource = cmd.ExecuteDataTable("SELECT user_type_id,user_type FROM user_type_tbl")
    End Sub

    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        If txtname.Text.Trim = "" Then
            MessageBox.Show("Username can't be empty")
            Exit Sub
        End If
        If txtpwd.Text.Trim = "" Then
            MessageBox.Show("Password can't be empty")
            Exit Sub
        End If
        cmd.Parameters("@name") = txtname.Text
        cmd.Parameters("@pwd") = txtpwd.Text
        cmd.Parameters("@id") = MainMenu.userid
        cmd.ExecuteNonQuery("UPDATE user_tbl set username=@name,password=@pwd WHERE user_id=@id")
        MessageBox.Show("Update Sucess")
    End Sub
End Class